package shujujiegou.lianbiao;

import org.junit.Test;
import org.junit.jupiter.api.DisplayName;

public class test {
    @Test
    @DisplayName("测试遍历和头插法")
    public void test1() {
        SinglyLinkedList singlyLinkedList = new SinglyLinkedList();
        singlyLinkedList.addFirst(1);
        singlyLinkedList.addFirst(2);
        singlyLinkedList.addFirst(3);
        singlyLinkedList.addFirst(4);
        singlyLinkedList.addFirst(5);
        singlyLinkedList.loop(value1 ->
                System.out.println(value1)
        );
    }

    @Test
    @DisplayName("测试迭代器遍历")
    public void test2() {
        SinglyLinkedList singlyLinkedList = new SinglyLinkedList();
        singlyLinkedList.addFirst(1);
        singlyLinkedList.addFirst(2);
        singlyLinkedList.addFirst(3);
        singlyLinkedList.addFirst(4);
        singlyLinkedList.addFirst(5);
        for (Integer value : singlyLinkedList) {
            System.out.println(value);
        }
    }

    @Test
    @DisplayName("测试头插入法&&测试利用索引查找")
    public void test3() {
        SinglyLinkedList singlyLinkedList = new SinglyLinkedList();
        singlyLinkedList.addLast(1);
        singlyLinkedList.addLast(2);
        singlyLinkedList.addLast(3);
        singlyLinkedList.addLast(4);
        singlyLinkedList.addLast(5);
        for (Integer value : singlyLinkedList) {
            System.out.println(value);
        }
        System.out.println(singlyLinkedList.get(8));
    }

    @Test
    @DisplayName("测试insert")
    public void test4() {
        SinglyLinkedList singlyLinkedList = new SinglyLinkedList();
        singlyLinkedList.addLast(1);
        singlyLinkedList.addLast(2);
        singlyLinkedList.addLast(3);
        singlyLinkedList.addLast(4);
        singlyLinkedList.addLast(5);
        singlyLinkedList.insert(1,2);
        for (Integer integer : singlyLinkedList) {
            System.out.println(integer);
        }
    }
     @Test
    @DisplayName("测试删除第一个元素")
    public void test5() {
        SinglyLinkedList singlyLinkedList = new SinglyLinkedList();
        singlyLinkedList.addLast(1);
        singlyLinkedList.addLast(2);
        singlyLinkedList.addLast(3);
        singlyLinkedList.addLast(4);
        singlyLinkedList.addLast(5);
        singlyLinkedList.removedFirst();
        for (Integer integer : singlyLinkedList) {
            System.out.println(integer);
        }
    }


}
